//
//  ViewController.swift
//  PAAnydoorSwift
//
//  Created by elegance on 15/12/23.
//  Copyright © 2015年 elegance. All rights reserved.
//

import UIKit
import Alamofire
import SwiftyJSON

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        let pluginParameters : Dictionary = ["deviceId":"0E02254D-A365-49C8-85A1-00C97F30418E","dataVersion":"ef910cec4dbef96fcc3e6414652a3622","appVersion":"1.0","osVersion":"9.1","sdkVersion":"3.3.0.0","deviceType":"ios_unknow","appId":"PA01100000000_01_SDK"]
        
        Alamofire.request(.POST, "https://maam-dmzstg2.pingan.com.cn:9041/maam/getPluginList.do", parameters: pluginParameters)
            .responseString { response in
                
                let resultData  = response.result.value?.dataUsingEncoding(NSUTF8StringEncoding)
                let resultJson = JSON(data:resultData!)
                
                let code = resultJson["code"]
                if code == "0"
                {
                    let dataVersion = resultJson["body"]["dataVersion"]
                    print("dataVersion=== \(dataVersion)")
                    
                    let dataValue = resultJson["body"]["data"]
                    let dataValueArr = dataValue.arrayObject
                    let PluginModels = PluginModel.jsonToModelList(dataValueArr) as! Array<PluginModel>;
                    
                    for plugin : PluginModel in PluginModels
                    {
                        print("bgImgs:\(plugin.bgImgs)")
                        print("category:\(plugin.category)")
                        print("detail:\(plugin.detail)")
                        print("detailColor:\(plugin.detailColor)")
                        print("displayScenarios:\(plugin.displayScenarios)")
                        print("h5BaseUrl:\(plugin.h5BaseUrl)")
                        print("hasMessage:\(plugin.hasMessage)")
                        print("iconColor:\(plugin.iconColor)")
                        print("iconEndTime:\(plugin.iconEndTime)")
                        print("iconImg:\(plugin.iconImg)")
                        print("iconStartTime:\(plugin.iconStartTime)")
                        print("iconTimeSpan:\(plugin.iconTimeSpan)")
                        print("iconType:\(plugin.iconType)")
                        print("iconVersion:\(plugin.iconVersion)")
                        print("isHide:\(plugin.isHide)")
                        print("isNewPlugin:\(plugin.isNewPlugin)")
                        print("isOperationMagnet:\(plugin.isOperationMagnet)")
                        print("needLogin:\(plugin.needLogin)")
                        print("pluginUid:\(plugin.pluginUid)")
                        print("pluginVersion:\(plugin.pluginVersion)")
                        print("title:\(plugin.title)")
                        print("titleColor:\(plugin.titleColor)")
                        print("type:\(plugin.type)")
                        print("updatedDate:\(plugin.updatedDate)")
                        print("url:\(plugin.url)")
                        print("url4BadNetWork:\(plugin.url4BadNetWork)")
                        print("shape:\(plugin.shape)")
                        print("h5Cacheable:\(plugin.h5Cacheable)")
                        print("colSpan:\(plugin.colSpan)")
                        print("parentPluginUid:\(plugin.parentPluginUid)")
                        print("orderIndex:\(plugin.orderIndex)")
                        print("messageUrl:\(plugin.messageUrl)")

                    }
//                    print(PluginModels)
                }
                
            }
            .responseJSON { response in
                print("\(response.result.value)")
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

@objc(PluginModel)
class PluginModel:D3Model
{
    var bgImgs:Array<String>!
    var category:String!
    var colSpan:String!
    var company:String!
    var detail:String!
    var detailColor:String!
    var displayScenarios:String!
    var h5BaseUrl:String!
    var h5Cacheable:String!
    var hasMessage:String!
    var icon:String!
    var iconColor:String!
    var iconEndTime:String!
    var iconImg:String!
    var iconStartTime:String!
    var iconTimeSpan:String!
    var iconType:String!
    var iconVersion:String!
    var isHide:String!
    var isNewPlugin:String!
    var isOperationMagnet:String!
    var md5Sign:String!
    var name:String!
    var needLogin:String!
    var pluginUid:String!
    var pluginVersion:String!
    var title:String!
    var titleColor:String!
    var type:String!
    var updatedDate:String!
    var url:String!
    var url4BadNetWork:String!
    var userSystem:String!
    var version:String!
    var shape:String!
    var parentPluginUid:String!
    var orderIndex:String!
    var messageUrl:String!
}

